/**
 * 
 */
package org.log4jconfig.xml.editor;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
import org.eclipse.jface.text.quickassist.IQuickAssistAssistant;
import org.eclipse.jface.text.quickassist.QuickAssistAssistant;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.wst.sse.core.text.IStructuredPartitions;
import org.eclipse.wst.xml.core.text.IXMLPartitions;
import org.eclipse.wst.xml.ui.StructuredTextViewerConfigurationXML;
import org.log4jconfig.xml.editor.contentassist.AttributeValueContentAssistProcessor;
import org.log4jconfig.xml.editor.hyperlink.AppenderRefValueHyperlinkDetector;
import org.log4jconfig.xml.editor.hyperlink.ClassTypeHyperlinkDetector;
import org.log4jconfig.xml.editor.quickfix.AnyDeprecatedElementQuickAssistProcessor;

/**
 * @author Xi
 * 
 */
public class Log4jXMLStructuredTextViewerConfiguration extends StructuredTextViewerConfigurationXML {

	/**
	 * Instantiates a new log4j xml structured text viewer configuration.
	 */
	public Log4jXMLStructuredTextViewerConfiguration() {
		super();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @seeorg.eclipse.wst.xml.ui.StructuredTextViewerConfigurationXML#
	 * getContentAssistProcessors(org.eclipse.jface.text.source.ISourceViewer,
	 * java.lang.String)
	 */
	@Override
	public IContentAssistProcessor[] getContentAssistProcessors(ISourceViewer sourceViewer, String partitionType) {
		IContentAssistProcessor[] processors;
		if (partitionType == IStructuredPartitions.DEFAULT_PARTITION || partitionType == IXMLPartitions.XML_DEFAULT) {
			processors = new IContentAssistProcessor[] { new AttributeValueContentAssistProcessor() };
		} else {
			processors = super.getContentAssistProcessors(sourceViewer, partitionType);
		}
		return processors;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @seeorg.eclipse.ui.editors.text.TextSourceViewerConfiguration#
	 * getHyperlinkDetectors(org.eclipse.jface.text.source.ISourceViewer)
	 */
	@Override
	public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
		IHyperlinkDetector[] detectors = super.getHyperlinkDetectors(sourceViewer);
		List<IHyperlinkDetector> d = new ArrayList<IHyperlinkDetector>(detectors.length + 2);
		for (IHyperlinkDetector detector : detectors) {
			d.add(detector);
		}
		d.add(new ClassTypeHyperlinkDetector());
		d.add(new AppenderRefValueHyperlinkDetector());
		return d.toArray(new IHyperlinkDetector[d.size()]);
	}

	
	@Override
	public IQuickAssistAssistant getQuickAssistAssistant(
			ISourceViewer sourceViewer) {
		QuickAssistAssistant quickAssistAssistant = new QuickAssistAssistant();
		quickAssistAssistant.setQuickAssistProcessor(new AnyDeprecatedElementQuickAssistProcessor());
		return quickAssistAssistant;
	}

}
